package homework;

public class MyTicket implements Runnable{
    private static int ticket =100;
    private static Object obj = new Object();

    @Override
    public void run() {
        while (true){
            synchronized (obj) {
                if(ticket<=0){
                    break;
                }else{
                    try {
                        Thread.sleep(300);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+"现在还剩下"+ticket+"张电影票");
                    ticket--;
                }
            }
        }
    }
}
